<!DOCTYPE html>
<html th:replace="~{layout :: layout(~{::title}, ~{::section})}">
<head>
<title>文章编辑页面</title>

</head>
<body>
<section>
	<form th:action="@{/admin/article/edit}" method="post" th:object="${article}">
		<input type="hidden" name="id" th:value="${article?.id}">
		<div class="row">
			<div class="col-xs-2"
				 style="height: 35px; display: flex; justify-content: flex-end; line-height: 35px">
				文章分类</div>
			<div class="col-xs-6">
				<select class="form-control" name="catId" th:value="${article?.catId}">
					<option th:each="cat:${articleCatList}" th:value="${cat.id}" th:selected="${article.catId eq cat.id}" selected="selected" th:text="${cat.catName}"></option>
				</select>
			</div>
			<div class="col-xs-4"></div>
		</div>
		<div class="row">
			<div class="col-xs-2"
				 style="height: 35px; display: flex; justify-content: flex-end; line-height: 35px">
				文章标题</div>
			<div class="col-xs-6">
				<input class="form-control" type="text" placeholder="请输入文章标题" required="required"
					   name="title" th:value="${article?.title}">
			</div>
			<div class="col-xs-4"></div>
		</div>

		<div class="row">
			<div class="col-xs-2"
				 style="height: 35px; display: flex; justify-content: flex-end; line-height: 35px">
				文章内容</div>
			<div class="col-xs-10">
					<textarea id="content" name="content"
							  class="form-control kindeditor" th:text="${article?.content}"></textarea>
			</div>

		</div>

		<div class="row">
			<div class="col-xs-2"
				 style="height: 35px; display: flex; justify-content: flex-end; line-height: 35px">
			</div>
			<div class="col-xs-6">
				<button class="btn btn-primary btn-block" type="submit">保存</button>
			</div>
			<div class="col-xs-4"></div>
		</div>

	</form>
	<script type="text/javascript"
			th:src="@{/zui/lib/tinymce/js/tinymce/tinymce.min.js}"></script>
	<script>

			tinymce.init({
			selector : '#content',
			height : 400,
			language : 'zh_CN',
			plugins : ['advlist','autolink','link','image'], //数组方式
			toolbar: false,
			images_upload_handler: function (blobInfo, succFun, failFun) {
			var xhr, formData;
			var file = blobInfo.blob();//转化为易于理解的file对象
			xhr = new XMLHttpRequest();
			xhr.withCredentials = false;
			xhr.open('POST', '/admin/upload/cosupload');
			xhr.onload = function() {
			var json;
			if (xhr.status != 200) {
			failFun('HTTP Error: ' + xhr.status);
			return;
		}
			json =JSON.parse(xhr.responseText);
			/*  if (!json || typeof json.location != 'string') {
                 failFun('Invalid JSON: ' + xhr.responseText);
                 return;
             } */


			if(json.status==1){

			//console.log(json.path)
			succFun(json.path);
		}
			else{
			failFun('Invalid JSON: ' + xhr.responseText);
			return;

		}

		};
			formData = new FormData();
			formData.append('file', file, file.name );//此处与源文档不一样
			xhr.send(formData);
		}

		})
	</script>
</section>

</body>
</html>